<?php

/**
 * 用户竞猜记录
 * @since 2017-10-17
 */
class user_guessing_logModel extends NewModel {

    public function multiAddLog($guessing_log_id, $win_guessing_id, $win_ratio) {
        $create_time = NOW_TIME;
        $create_date = to_date($create_time, 'Y-m-d H:i:s');
        $table = DB_PREFIX . 'user_guessing_log';
        self::$sql = "INSERT INTO $table (
                `guessing_log_id`,
                `user_id`,
                `xiacai_id`,
                `guessing_id`,
                `money`,
                `create_time`,
                `create_date`,
                `is_bet`
            ) SELECT
                '$guessing_log_id' AS `game_log_id`,
                `user_id`,
                `xiacai_id`,
                '0' AS `guessing_id`,
                (SUM(l.`money`) * $win_ratio) AS `money`,
                '$create_time' AS `create_time`,
                '$create_date' AS `create_date`,
                '2' AS `is_bet`
            FROM
                $table AS l
            WHERE
                l.is_bet = 1
            AND `guessing_log_id` = $guessing_log_id
            AND `guessing_id` = $win_guessing_id
            GROUP BY
                `user_id`";
        debugmsg('user_guessing_logModel::multiAddCoinForGuessing()', self::$sql);
        return Connect::exec(self::$sql);
    }

    public function addLog($guessing_log_id, $xiacai_id, $money, $user_id, $guessing_id, $is_bet = 1) {
        $create_time = NOW_TIME;
        $create_date = to_date($create_time, 'Y-m-d H:i:s');
        $data = array(
            'guessing_log_id' => $guessing_log_id,
            'user_id' => $user_id,
            'xiacai_id' => $xiacai_id,
            'money' => $money,
            'guessing_id' => $guessing_id,
            'create_time' => $create_time,
            'create_date' => $create_date,
            'is_bet' => $is_bet, // 1:下注,2:收益
        );
        return $this->insert($data);
    }

}
